﻿using System;
using System.Security.Principal;
using System.Web;
using EPiServer.Personalization.VisitorGroups;

namespace CriteriaPack.ABTestingCriterion
{
    [VisitorGroupCriterion(
        Category = "Optimisation",
        Description = "Matches the current request for the editor set percentage. Allows for A/B content tests in conjunction with other critieria",
        DisplayName = "A/B Testing")]
    public class ABTestingCriterion : CriterionBase<ABTestingModel>
    {
        public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
        {
            var rnd = new Random();
            int random = rnd.Next(0, 100);

            return Model.MatchPercentage <= random;
        }
    }
}